package org.example.ExperimentFifth;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

public class bookList {
    public static void main(String[] args) {
//        创建存储书籍和作者的Arraylist
        ArrayList<String> books = new ArrayList<>();
        books.add("Java Programming");
        books.add("Data Structures");
        books.add("Operating Systems");
        books.add("Computer Networks");
//        存入到hashMap中输出打印
        HashMap<String, String> bookAuthors = new HashMap<>();
        bookAuthors.put("Java Programming", "Author A");
        bookAuthors.put("Data Structures", "Author B");
        bookAuthors.put("Operating Systems", "Author C");
        bookAuthors.put("Computer Networks", "Author D");
        // 遍历ArrayList并使用HashMap获取并打印输出每本书籍的作者
        for (String book : books) {
            System.out.println(book + " 的作者是 " + bookAuthors.get(book));
        }
        // 创建一个HashSet存储书籍的作者名称并打印所有作者（确保没有重复作者）
        HashSet<String> uniqueAuthors = new HashSet<>(bookAuthors.values());
        System.out.println("所有作者: " + uniqueAuthors);
    }
}
